#pragma once

#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "Public.h"

namespace sevent{

class Address {
public:
	Address();
	Address(const std::string ip, const int port);
	Address(const Address & other);
	~Address();
	
	int port();
	std::string ip();

	int setAddress(const std::string ip, const int port);
	int length() {return sizeof(_addr);}

	struct sockaddr_in &addr() {return _addr;}
private:
	struct sockaddr_in _addr;
};

class Connect;

int Poll(int fd, short events, int timeout);
int Read(int fd, void *buf, size_t len, int timeout);
int Write(int fd, void *buf, size_t len, int timeout);

int tcpRead(int fd, void *buf, int len, int timeout);
int tcpWrite(int fd, void *buf, int len, int timeout);
int tcpConnect(Address &peerAddr);
//int tcpAccept(int fd, struct sockaddr *addr, socklen_t * len);
//int tcpAccept(int fd, vector<int> &fdVec, vector<Address> &addrVec);
int tcpAccept(int fd, std::vector<Connect *> &connectVec);
int tcpClose(int fd);
int tcpAlive(int fd);

int tcpEpollWait(int fd, struct epoll_event *events, int maxevent, int timeout);
int tcpEpollAdd(int epfd, int fd, void *ptr, int events);

}
